package tt.com.warehousemanager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tt.com.common.model.YxCommonPurchaseServe;
import tt.com.warehousemanager.mapper.PurchaseServeMapper;
import tt.com.warehousemanager.service.PurchaseServeService;

import java.util.Date;
import java.util.List;

/**
 * @author Czycka
 * @date 2022/8/25 2:43
 * @description 采购单明细服务实现类
 */
@Service
public class PurchaseServeServiceImpl extends ServiceImpl<PurchaseServeMapper, YxCommonPurchaseServe> implements PurchaseServeService {
    @Override
    public Boolean deletePurchaseServe(String purchaseNo, String deleteUserId) {
        QueryWrapper<YxCommonPurchaseServe> wrapper = new QueryWrapper<>();
        wrapper.eq("organ_id", purchaseNo);
        List<YxCommonPurchaseServe> purchaseServeList = baseMapper.selectList(wrapper);

        for (YxCommonPurchaseServe purchaseServe : purchaseServeList) {
            // 设置删除时间
            purchaseServe.setDeleteTime(new Date());
            // 设置删除操作人id
            purchaseServe.setDeleteUserId(deleteUserId);
        }
        this.updateBatchById(purchaseServeList);

        return this.remove(wrapper);
    }
}